<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${path}/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="${path}/css/nav.css">
    <meta charset="UTF-8">
    <title>绑定经纪人</title>
    <style>
        .jingjirentupian img {
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>

<%@ include file="../nav/headnav.jsp" %>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-8">
            <div>
                <form class="bs-example bs-example-form" role="form">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="input-group">
                                <input type="text" class="form-control" id="agent_search">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button" id="agent_btn">搜索</button>
                                </span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="col-md-2" style="margin-left: -200px">
        </div>
    </div>
</div>

<div class="container-fluid" style="margin-top: 50px">
    <div class="table-responsive jingjirentupian">
        <table class="table">
            <h2>经纪人信息</h2><span style="color: red;font-size: medium">绑定经纪人才能发布房源</span>
            <thead>
            <tr>
                <th>序号</th>
                <th>经纪人照片</th>
                <th>经纪人名字</th>
                <th>经纪人性别</th>
                <th>经纪人手机</th>
                <th>经纪人评分</th>
                <th>经纪人执照</th>
                <th>选择经纪人</th>
            </tr>
            </thead>
            <tbody>
            <c:if test="${page.list!=null}">
                <c:forEach items="${page.list}" var="a" varStatus="vs">
                    <tr>
                        <td>${vs.count}</td>
                        <td><img src="http://${path2}/img/agents.jpg"></td>
                        <td>${a.name}</td>
                        <c:if test="${a.gender=='true'}">
                            <td>男</td>
                        </c:if>
                        <c:if test="${a.gender=='false'}">
                            <td>女</td>
                        </c:if>
                        <td>${a.phone}</td>
                        <td>${a.grade}</td>
                        <td><img src="http://${path2}/img/zhizhao.jpg"></td>
                        <td>
                            <button name="agentId" id="agentId"
                                    class="btn btn-primary btn-lg" data-toggle="modal"
                                    data-target="#myModal${a.id}">绑定</button>
                        </td>

                        <div class="modal fade" id="myModal${a.id}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                            &times;
                                        </button>
                                        <h4 class="modal-title" id="myModalLabel">
                                            请选择出租方式
                                        </h4>
                                    </div>
                                    <div class="modal-body">
                                        <div class="row">
                                            <div class="col-md-offset-3" style="float: left">
                                                <button style="text-decoration: none;font-size: x-large" onclick="bindWhole(this,${a.id})">整租</button>
                                            </div>
                                            <div class="col-md-offset-3" style="float: left">
                                                <button style="text-decoration: none;font-size: x-large" onclick="bindTogether(this,${a.id})">合租</button>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal -->
                        </div>
                    </tr>
                </c:forEach>
            </c:if>

            <c:if  test="${agents!=null}">
                <c:forEach items="${agents}" var="a" varStatus="vs">
                    <tr>
                        <td>${vs.count}</td>
                        <td><img src="http://${path2}/img/agents.jpg"></td>
                        <td>${a.name}</td>
                        <c:if test="${a.gender=='true'}">
                            <td>男</td>
                        </c:if>
                        <c:if test="${a.gender=='false'}">
                            <td>女</td>
                        </c:if>
                        <td>${a.phone}</td>
                        <td>${a.grade}</td>
                        <td><img src="http://${path2}/img/zhizhao.jpg"></td>
                        <td>
                            <button name="agentId" id="agentId"
                                    class="btn btn-primary btn-lg" data-toggle="modal"
                                    data-target="#myModal${a.id}">绑定</button>
                        </td>

                        <div class="modal fade" id="myModal${a.id}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                            &times;
                                        </button>
                                        <h4 class="modal-title" id="myModalLabel">
                                            请选择出租方式
                                        </h4>
                                    </div>
                                    <div class="modal-body">
                                        <div class="row">
                                            <div class="col-md-offset-3" style="float: left">
                                                <button style="text-decoration: none;font-size: x-large" onclick="bindWhole(this,${a.id})">整租</button>
                                            </div>
                                            <div class="col-md-offset-3" style="float: left">
                                                <button style="text-decoration: none;font-size: x-large" onclick="bindTogether(this,${a.id})">合租</button>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal -->
                        </div>
                    </tr>
                </c:forEach>
            </c:if>
            </tbody>
        </table>

        <!--分页begin-->
        <div style="text-align: center;display: ${zw}">
            <ul class="pagination">
                <li><a href="javascript:next_page(1)">首页</a></li>

                <c:if test="${page.pageNum<=1}">
                    <li class="disabled"><a href="#">&laquo;</a></li>
                </c:if>

                <c:if test="${page.pageNum>1}">
                    <li><a href="javascript:next_page(${page.pageNum-1})">&laquo;</a></li>
                </c:if>

                <c:if test="${page.pageNum+2<=page.pages}">
                    <c:set var="endPage" value="${page.pageNum+2}"></c:set>
                    <c:set var="startPage" value="${page.pageNum}"></c:set>
                </c:if>

                <c:if test="${page.pageNum+2>page.pages}">
                    <c:set var="endPage" value="${page.pages}"></c:set>
                    <c:set var="startPage" value="${page.pages-2}"></c:set>
                </c:if>

                <c:forEach begin="${startPage<=0?1:startPage}" end="${endPage}" var="v">
                    <li <c:if test="${page.pageNum == v}">class="active"</c:if></li> <a
                        href="javascript:next_page(${v})">${v}</a></li>
                </c:forEach>


                <c:if test="${page.pageNum<page.pages}">
                    <li><a href="javascript:next_page(${page.pageNum+1})">&raquo;</a></li>
                </c:if>

                <c:if test="${page.pageNum>=page.pages}">
                    <li class="disabled"><a href="#">&raquo;</a></li>
                </c:if>


                <li><a href="javascript:next_page(${page.pages})">尾页</a></li>
                <li><a href="#">当前页${page.pageNum}/${page.pages}总页</a></li>
            </ul>
        </div>
        <!--分页end-->

    </div>

    <!-- 模态框（Modal） -->


    <%--    <a href="/taofang/post/home?id=${a.id}"><button class="btn btn-info" >提交</button></a>--%>
</div>

<!--底部导航栏-->
<%@ include file="../nav/footnav.jsp" %>
<!--底部导航栏end-->


<script src="${path}/plugins/jquery-3.4.1.js"></script>
<script src="${path}/plugins/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<script>
    $(function () {
        $("#agent_btn").click(function () {
            let sea = $("#agent_search").val();
            //alert(sea)
            window.location = "/taofang/agent/select/" + sea;
        });
    });

    function bindWhole(obj, id) {

        let datas = {"agent_id": id}

        $.get('/taofang/agent/bindWhole/'+id, datas, function (data) {
            window.location = "/taofang/agent/bindWhole/" + id;
        })

    }

    function bindTogether(obj, id) {

        let datas = {"agent_id": id}

        $.get('/taofang/agent/bindTogether/'+id, datas, function (data) {
            window.location = "/taofang/agent/bindTogether/" + id;
        })

    }

    //分页
    function next_page(page) {
        // alert(page)

        let sea = $("#agent_search").val();

        sea = sea == "" ? null : sea;
        //alert(sea)

        window.location = "/taofang/agent/select/" + sea + "/" + page;
    }
</script>

</body>
</html>